package com.eling.elcms.travel.service.impl;

import com.eling.elcms.core.service.impl.GenericManagerImpl;
import com.eling.elcms.core.util.PropertyUtils;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.travel.dao.IProductRuleDao;
import com.eling.elcms.travel.model.ProductRule;
import com.eling.elcms.travel.model.ProductRuleDetail;
import com.eling.elcms.travel.service.IProductRuleDetailManager;
import com.eling.elcms.travel.service.IProductRuleManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ProductRuleManagerImpl  extends GenericManagerImpl<ProductRule, Long> implements IProductRuleManager{

	IProductRuleDao productRuleDao;
	@Autowired
	private IProductRuleDetailManager productDetailManager;
	
	@Autowired
	public void setDao(IProductRuleDao dao) {
        this.dao = dao;
        this.productRuleDao = dao;
    }
	
	@Override
	public ProductRule updata(ProductRule product) {
		Boolean b=product.getSales();
		if(b){
			product.setSales(false);
		}else{
			product.setSales(true);
		}
		return super.save(product);
	}

	@Override
	public Msg deleteAll(Long pkProduct) {
		ProductRuleDetail pd=new ProductRuleDetail();
		PropertyUtils.setProperty(pd, "productRule.pkProductRule",pkProduct);
		List<ProductRuleDetail> lsit=productDetailManager.query(pd);
		productDetailManager.remove(lsit);
		remove(pkProduct);
		return new Msg("删除成功");
	}

}
